package BookSystem;

import java.time.LocalDateTime;
import java.util.Random;
import java.util.Scanner;

public class BookStore {
    static Book[] books=new Book[4];
    static {
        books[0]=new Book(1,"红楼梦",50,20);
        books[1]=new Book(2,"水浒传",50,20);
        books[2]=new Book(3,"西游记",50,20);
        books[3]=new Book(4,"三国演义",50,20);
    }
    public static void main(String[] args) {
        //将所有图书显示出来
        showBooks(books);
        //买书
        Person p= new Person("张三");
        Book book=p.buy(books);
        System.out.println(book.getId()+book.getName());
        //结算
        count(p,book);
    }
    //结算
    private static void count(Person p,Book books) {

        //获得当前时间

        System.out.println("购买时间"+LocalDateTime.now());
        System.out.println("请输入购买数量");
        Scanner sc =new Scanner(System.in);

        int num = sc.nextInt();
        //利用随机数产生订单编号
        Random random=new Random();
        int orderNum=random.nextInt();
        System.out.println("订单的标编:"+Math.abs(orderNum));
        System.out.println("会员"+p.getName());
        //输出购买的图书信息
        System.out.println("图书名称:"+books.getName()+"\n图书单价:"+books.getPrice()+"\n购买数量:"+num+"\n总计:"+books.getPrice()*num);




    }


    private static void showBooks(Book[] books) {
        System.out.println("编号\t图书名称\t单价\t库存");
        //数组遍历
        for(int i=0;i<books.length;i++) {
            Book book = books[i];
            System.out.println(book.getId()+"\t"+book.getName()+"\t"+book.getPrice()+"\t"+book.getStorage());
        }
    }
    //结算


}
